package com.bj.dz.service.impl;

import com.bj.dz.entity.ReleaseSubtask;
import com.bj.dz.mapper.ReleaseSubtaskMapper;
import com.bj.dz.service.ReleaseSubtaskService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ReleaseSubtaskServiceImpl implements ReleaseSubtaskService {

    @Resource
    private ReleaseSubtaskMapper releaseSubtaskMapper;

    public ReleaseSubtask getReleaseSubtaskById(Integer id){
        return releaseSubtaskMapper.getReleaseSubtaskById(id);
    }

    public List<ReleaseSubtask>	getReleaseSubtaskListByMap(Map<String,Object> param){
        return releaseSubtaskMapper.getReleaseSubtaskListByMap(param);
    }

    public Integer getReleaseSubtaskCountByMap(Map<String,Object> param){
        return releaseSubtaskMapper.getReleaseSubtaskCountByMap(param);
    }

    @Transactional
    public boolean addReleaseSubtask(ReleaseSubtask releaseSubtask){
            return releaseSubtaskMapper.insertReleaseSubtask(releaseSubtask)>0?true:false;
    }

    @Transactional
    public boolean modifyReleaseSubtask(ReleaseSubtask releaseSubtask){
        return releaseSubtaskMapper.updateReleaseSubtask(releaseSubtask)>0?true:false;
    }

    @Transactional
    public boolean deleteReleaseSubtaskById(Integer id){
        return releaseSubtaskMapper.deleteReleaseSubtaskById(id)>0?true:false;
    }

    public Page<ReleaseSubtask> queryReleaseSubtaskPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = releaseSubtaskMapper.getReleaseSubtaskCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ReleaseSubtask> releaseSubtaskList = releaseSubtaskMapper.getReleaseSubtaskListByMap(param);
        page.setRows(releaseSubtaskList);
        return page;
    }

}
